import java.util.Scanner;
/**
 * Write a description of class lcs here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class TJU_3601
{
    static String[] a1;
    static String[] a2;
  public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int x = sc.nextInt();
      a1 = new String[n];
      a2 = new String[x];
      for(int i = 0; i < n; i++){
          a1[i] = sc.next();
        }
      for(int i = 0; i < x; i++){
          a2[i] = sc.next();
        }
        System.out.println(solve());
    }
  public static int solve(){
      int ret=0;
      for(int i = 0; i < a1.length; i++){
          for(int j = 0; j < a2.length; j++){
              int temp=0;
              for(int k = 0; i + k < a1.length && j+k < a2.length; k++){
                  if(!a1[i+k].equals(a2[j+k])){
                      break;
                    }
                    temp++;
                }
                ret = Math.max(temp, ret);
            }
        }
        return ret;
}
}